package com.pp.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pp.common.vo.SysResult;
import com.pp.web.model.vo.PostVO;
import com.pp.web.service.IPostService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/search")
public class SearchController {

    @Resource
    private IPostService postService;

    /**
     * 获得根据 keyword 查询的结果
     */
    @GetMapping
    public SysResult getSearchResults (
        @RequestParam("keyword") String keyword,
        @RequestParam("pageNum") Integer pageNum,
        @RequestParam("pageSize") Integer pageSize) {
        Page<PostVO> searchResults = postService.searchPostsByKeyword(
            keyword,
            new Page<>(pageNum, pageSize)
        );
        return SysResult.success(searchResults);
    }

}
